package com.qdu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qdu.commons.Result;
import com.qdu.entity.Pose;
import com.qdu.mapper.CompleteMapper;
import com.qdu.mapper.PoseMapper;
import com.qdu.service.IPoseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ellery2018
 * @since 2022-03-09
 */
@Service
@RequiredArgsConstructor
public class PoseServiceImpl extends ServiceImpl<PoseMapper, Pose> implements IPoseService {

    private final PoseMapper poseMapper;

    @Override

    public String makepose() {
        // 总记录数
        QueryWrapper<Pose> wrapper = Wrappers.query();

        int count = poseMapper.selectCount(wrapper);
// 随机数起始位置
        int randomCount =(int) (Math.random()*count);


        wrapper.orderByDesc("id");
        wrapper.last("limit "+String.valueOf(randomCount)+", 1");
        Pose randomPose = poseMapper.selectOne(wrapper);
        System.out.println(randomPose);
        return randomPose.getName();
    }
}
